<?php
class ZdssvsController extends AppController {

	var $name = 'Zdssvs';
    var $uses=array('Zdssv','Chidoansv');
	function index() {
        $id = $this->Session->read('chidoanht_id');
        //$id=13;
		$zdssvs=$this->Zdssv->find('all',array('conditions'=>array('chidoansv_id'=>$id)));
        $this->set('zdssvs', $zdssvs);
	}
    
    function dssv() {
        $id = $this->Session->read('chidoanht_id');
        $this->layout = 'excel';
		$zdssvs=$this->Zdssv->find('all',array('conditions'=>array('chidoansv_id'=>$id)));
        $this->set('zdssvs', $zdssvs);
	}
    function dscdsv(){
        $cds=$this->Chidoansv->find('all',array('conditions'=>array('Chidoansv.khoahoc_id <>'=>null)));
        $this->set('cds', $cds);
        
    }
    function multiexp(){
        if(!empty($this->data)){
            //pr($this->data);exit;
            $cdids = array();              
    		foreach($this->data['Zdssv']['cdid'] as $id => $value){
    			if($value == 1){
    	  		  $cdids[] = $id;
    			}
    		}
            //$zdssvs=$this->Zdssv->find('all',array('conditions'=>array('or'=>array('Zdssv.chidoansv_id'=>$cdids)),'recursive'=>-1));
            $results=array();
            foreach ($cdids as $cdid){
                $results[$cdid]=$this->Zdssv->find('all',array('conditions'=>array('Zdssv.chidoansv_id'=>$cdid),'recursive'=>-1));
            }
            $this->set('cdids',$cdids);
            $this->set('results',$results);
            $this->layout = 'excel';
            //$this->redirect(array('action' => 'multiexp'));
        }
        
    }
    
    function dssvw() {
        //$id = $this->Session->read('chidoanht_id');
        $id=13;
        $this->layout = 'word';
		$zdssvs=$this->Zdssv->find('all',array('conditions'=>array('chidoansv_id'=>$id),'recursive'=>-1));
        $this->set('zdssvs', $zdssvs);
	}
    
    
	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid zdssv', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('zdssv', $this->Zdssv->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Zdssv->create();
			if ($this->Zdssv->save($this->data)) {
				$this->Session->setFlash(__('The zdssv has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The zdssv could not be saved. Please, try again.', true));
			}
		}
		$chidoansvs = $this->Zdssv->Chidoansv->find('list');
		$tongiaos = $this->Zdssv->Tongiao->find('list');
		$phuongxas = $this->Zdssv->Phuongxa->find('list');
		$dantocs = $this->Zdssv->Dantoc->find('list');
		$this->set(compact('chidoansvs', 'tongiaos', 'phuongxas', 'dantocs'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid zdssv', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Zdssv->save($this->data)) {
				$this->Session->setFlash(__('The zdssv has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The zdssv could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Zdssv->read(null, $id);
		}
		$chidoansvs = $this->Zdssv->Chidoansv->find('list');
		$tongiaos = $this->Zdssv->Tongiao->find('list');
		$phuongxas = $this->Zdssv->Phuongxa->find('list');
		$dantocs = $this->Zdssv->Dantoc->find('list');
		$this->set(compact('chidoansvs', 'tongiaos', 'phuongxas', 'dantocs'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for zdssv', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Zdssv->delete($id)) {
			$this->Session->setFlash(__('Zdssv deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Zdssv was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
